#include <iostream>
#include <iterator>
#include <algorithm>
#include <ctime>
#include <cstring>
#include <cstdlib>

using namespace std;

class mi_rand
{
    public:
        mi_rand (int start_pos, int end_pos) : a(start_pos), b(end_pos) 
        {
            if (a > b) swap(a,b);
            srand ((unsigned) time(NULL));
        }

        unsigned operator () () 
        {
            return rand() % (b-a+1) + a;
        }

    private:
        int a, b;
};

int linearSearch (int *array, int key, int size)
{
    static int index = 0;
    if (size == 0) 
    {
        index = 0;
        return -1;
    }
    if (*array == key) 
    {
        int rt = index;
        index = 0;
        return rt;
    }
    index++;
    return linearSearch (array + 1, key, size - 1);
}

int main()
{
    const int SIZE = 10;
    int array[SIZE];
    generate_n (array, SIZE, mi_rand(10,100));
    
    copy (array, &array[SIZE], 
          ostream_iterator<int> (cout, " "));
    cout << endl;

    cout << endl << linearSearch (array, array[2], SIZE) << endl;

    return 0;
}

